function AutoScroll() {
    var _scroll = $("#slide>ul");
    //ul往左边移动300px
    _scroll.animate({marginLeft:"-178px"}, 1000, function () {
        //把第一个li丢最后面去
        _scroll.css({marginLeft:0}).find("li:first").appendTo(_scroll);
    });
}

function checkDom(object) {
    if (typeof object == "undefind") return false;
    return true;
}
$(function () {


    if (checkDom($("#currentUser"))) {
        $.get("/index.php/ajax/getCurrentUser", function (data) {
            data = eval("(" + data + ")");
            $("#currentUser").html(data.nickname);
        })
    }

    if (checkDom($("#button1"))) {
        $("#button1").bind("click", function () {
            var ids = "";
            $(".cbox").each(function () {
                if ($(this).attr("checked")) {
                    ids += $(this).val() + ",";
                }
            })
            if (ids.indexOf(",") != -1) {
                ids = ids.substr(0, ids.length - 1);
            }
            $.get("/index.php/admin/article/batchRemove", {"ids":ids}, function (data) {
                if (data == "success") {
                    alert("删除成功");
                    location.reload();
                }
            })
        })

    }

    if (checkDom($(".delete"))) {
        $(".delete").each(function () {
            $(this).bind("click", function () {
                $.get("/index.php/admin/articleType/delete", {"id":$(this).attr("name")}, function (data) {
                    if (data == "success") {
                        alert("删除成功");
                        location.reload();
                        return false;
                    }
                    if (data == "existArticle") {
                        alert("对不起，此分类下未删除或则转移的文章信息，请先处理");
                        return false;
                    }
                })
            })
        })
    }
//两秒后调用
    if (checkDom($("#slide"))) {
        var _scrolling = setInterval("AutoScroll()", 5000);
        $("#slide>ul").hover(function () {
            //鼠标移动DIV上停止
            clearInterval(_scrolling);
        }, function () {
            //离开继续调用
            _scrolling = setInterval("AutoScroll()", 5000);
        });

    }

    if ($("#nav").length > 0) {
        $("#nav").find("li").each(function () {
            $(this).bind("mouseover", function () {
                $(this).addClass("cur");
                var id = $(this).attr("name");
                $(this).addClass("cur");
                $(this).siblings("li").removeClass("cur");
                if (typeof id == 'undefined') {
                    $("#subNav").html("");
                    return false;
                }
                $.ajax({
                    url:"/index.php/ajax/loadSubType/" + id,
                    dataType:"html",
                    async:false,
                    type:"GET",
                    beforeSend:function (jqXHR, settings) {
                        //这里显示进度条
                    },
                    error:function (jqXHR, textStatus, errorThrown) {

                    },
                    success:function (data, textStatus, jqXHR) {
                        data = eval("(" + data + ")");
                        if (data.length > 0) {
                            //如果有子分类
                            var hcodess = "";
                            $.each(data, function (n, j) {
                                hcodess = hcodess + '<a href="/index.php/info/more/' + data[n].id + '/">' + data[n].name + '</a>&nbsp;|&nbsp;';
                            })
                            $("#subNav").html(hcodess.substr(0, hcodess.length - 13));
                        } else {
                            $("#subNav").html("");
                        }
                    }});

            })
        })
    }

})